package slhs.tempo.scriptGenerator;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

public class FileSelector {

    private String absolutePath;
    private JFileChooser fileChooser;
    private FileNameExtensionFilter filter;
    private String fileType;
    private String fileExtension;

    public FileSelector(String fileType, String fileExtension) {
	this.fileType = fileType;
	this.fileExtension = fileExtension;
    }

    protected String getSelectedFileAbsolutePath() {

	filter = new FileNameExtensionFilter(fileType, fileExtension);
	fileChooser = new JFileChooser();
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.addChoosableFileFilter(filter);

	int loadAction = fileChooser.showOpenDialog(null);
	if (loadAction == fileChooser.APPROVE_OPTION) {
	    File file = fileChooser.getSelectedFile();
	    absolutePath = file.getAbsolutePath();
	} else if (loadAction == fileChooser.CANCEL_OPTION) {
	    JOptionPane.showMessageDialog(null, "Select a Template file or choose a different experiment type",
		    "Error", JOptionPane.ERROR_MESSAGE);

	}
	return absolutePath;

    }
}
